import React from 'react';
import { connect } from 'dva';
import { Button } from 'antd'

const Dva = (props: any) => {
  const { dvaDemo } = props;
  const { users } = dvaDemo.list;
  const fetch = () => {
    const { dispatch } = props;
    dispatch({
      type: 'dvaDemo/list',
      payload: 'aa',
      callback: res => {
        console.log(res, '成功之后的回调');
      }
    })
  }

  console.log(dvaDemo, 'state里的数据');

  return (
    <div>
      <h1>dva</h1>
      <Button onClick={fetch}>hello</Button>
      {
        users && users && users.map(item => <p key={item}>{item}</p>)
      }
    </div>
  )
}

export default connect(({ dvaDemo, loading }) => ({
  dvaDemo,
  loading: loading.models.dvaDemo
}))(Dva);